package com.wsd.jing.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.wsd.jing.annotation.Account;
import com.wsd.jing.annotation.Mobile;
import com.wsd.jing.annotation.Status;
import com.wsd.jing.validator.group.InsertGroup;
import com.wsd.jing.validator.group.UpdateGroup;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.*;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;

/**
 * All rights Reserved, Designed By www.tom.com
 *
 * @author tom
 * @version 1.0.0
 * @projectName: jing
 * @packageName: com.wsd.jing.entity
 * @className: User
 * @description: 用户
 * @createDate 2022-11-14 07:02
 * @copyright 2022-11-14 07:02 www.tom.com Inc. All rights reserved.
 */
@Getter
@Setter
@ToString
@TableName("j_user")
@ApiModel(value = "User对象", description = "用户表")
public class User implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotNull(message = "用户ID不能为空", groups = UpdateGroup.class)
    @Null(message = "用户ID为空", groups = InsertGroup.class)
    @ApiModelProperty("用户ID")
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @NotBlank(message = "用户名称不能为空")
    @Length(max = 50, message = "用户名称不能超过50个字符")
    @ApiModelProperty("用户名称")
    @TableField("name")
    private String name;

    @Account(message = "账号必须字母开头，允许字母数字下划线,长度为5-20个字符")
    @ApiModelProperty("账号")
    @TableField("account")
    private String account;

    @JsonIgnore
    @ApiModelProperty("密码")
    @TableField("password")
    private String password;

    @Email(message = "邮箱格式不正确")
    @ApiModelProperty("邮箱")
    @TableField("email")
    private String email;

    @Mobile(message = "手机号码格式不正确")
    @ApiModelProperty("手机号码")
    @TableField("mobile")
    private String mobile;

    @NotNull(message = "状态不能为空")
    @Status(booleanValues = {false, true}, message = "状态格式不正确")
    @ApiModelProperty("状态=>0:锁定，1:有效")
    @TableField("status")
    private Boolean status;

    @NotNull(message = "性别不能为空")
    @Status(intValues = {0, 1, 2}, message = "性别格式不正确")
    @ApiModelProperty("性别=>0:女，1:男，2:未知")
    @TableField("sex")
    private Integer sex;

    @Length(max = 200, message = "头像不能超过200个字符")
    @ApiModelProperty("头像")
    @TableField("avatar")
    private String avatar;

    @Past(message = "出生日期为过去日期")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @ApiModelProperty("出生日期")
    @TableField("birthday")
    private LocalDate birthday;

    @NotNull(message = "部门ID不能为空")
    @ApiModelProperty("部门ID")
    @TableField("department_id")
    private Integer departmentId;

    @Length(max = 100, message = "描述不能超过100个字符")
    @ApiModelProperty("描述")
    @TableField("description")
    private String description;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("创建时间")
    @TableField("create_time")
    private LocalDateTime createTime;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @ApiModelProperty("修改时间")
    @TableField("update_time")
    private LocalDateTime updateTime;
}
